package com.itheim.chinamobileai.controller;

import jakarta.annotation.PostConstruct;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.openai.OpenAiEmbeddingModel;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;


@RestController
@RequestMapping("ai/service")
public class ChatController {
    @Autowired
    private ChatClient chatClient;
    @GetMapping(produces = "text/html;charset=UTF-8")
    public Flux<String> chat(String prompt , String chatId){
        // 创建一个会话
        return chatClient.prompt(prompt)
                .stream()
                .content();
    }

    @Autowired
    private VectorStore vectorStore;
    @Autowired
    private OpenAiEmbeddingModel embeddingModel;
    @PostConstruct
    public void RAG(){
        String rag = """
                [
                     {
                       "id": "rule_01",
                       "type": "合约期",
                       "condition": "合约期未满12个月",
                       "description": "提前更换套餐需支付剩余费用的10%作为违约金。"
                     },
                     {
                       "id": "rule_02",
                       "type": "携号转网",
                       "condition": "申请携号转网",
                       "description": "需满足：1. 无欠费 2. 当前套餐已到期 3. 非吉祥号段（如138/139开头）。"
                     }
                   ]
                """;
    }
}
